package com.springboot.frame.starter.pay.v2;

import lombok.Data;
import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author liheng
 * @ClassName V2
 * @Description
 * @date 2021-09-01 11:09
 */
@Data
public class V2 {
    /**
     * 加载证书 这里证书需要到微信商户平台进行下载
     */
    private String certPath;
    /**
     * 获取 API 密钥
     *
     * @return API密钥
     */
    private String apiKey;
    /**
     * 获取支付回调地址
     *
     * @return
     */
    private String notifyUrl;
    /**
     * 获取退款回调地址
     *
     * @return
     */
    private String notifyRefundUrl;
    /**
     * 签名方式，默认MD5
     */
    private WXPayConstants.SignType signType = WXPayConstants.SignType.MD5;

    public InputStream getCertStream() {
        // 需要证书释放
        byte[] certData;
        InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(this.certPath);
        try {
            certData = IOUtils.toByteArray(certStream);
            certStream.close();
        } catch (IOException e) {
            throw new RuntimeException("证书未找到");
        }
        return new ByteArrayInputStream(certData);
    }
}
